var t = getApp();

Page({
    data: {
        List1: [],
        lastid: 0,
        toastHidden: !0,
        confirmHidden: !0,
        isfrist: 1,
        loadHidden: !0,
        moreHidden: "none",
        msg: "——加载更多合同——",
        url: "con",
        base: "M",
        Listurl: "",
        TopName: "",
        bol: "",
        condition: !0
    },
    loadData: function(a, e) {
        wx.showToast({
            title: "数据加载中",
            icon: "loading",
            duration: 2e4
        });
        var o = this, i = this.data.Listurl;
        wx.request({
            url: t.url + "addon/" + i + "ContractList",
            data: {
                lastid: a,
                limit: e
            },
            method: "GET",
            header: {
                "Content-Type": "application/json",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(t) {
                if (wx.hideToast(), !t.data) return o.setData({
                    toastHidden: !1
                }), o.setData({
                    moreHidden: "none"
                }), o.setData({
                    msg: "——你尚没有创建此类合同——",
                    bol: !0
                }), !1;
                var e = t.data.length, i = a;
                o.setData({
                    lastid: t.data[e - 1].id
                });
                var n = t.data;
                0 == i && wx.setStorageSync("List1", n), o.setData({
                    List1: n,
                    bol: !0
                }), o.setData({
                    moreHidden: ""
                });
            },
            fail: function(t) {
                if (o.setData({
                    msg: "——当前网络异常，请检查网络或稍后再试——",
                    bol: !0
                }), wx.hideToast(), wx.showToast({
                    title: "无法连接网络",
                    icon: "loading",
                    duration: 2500
                }), 0 == a) {
                    var e = wx.getStorageSync("List1");
                    if (!e) {
                        o.setData({
                            List1: e
                        }), o.setData({
                            moreHidden: ""
                        });
                        var i = e.length;
                        o.setData({
                            lastid: e[i - 1].id
                        });
                    }
                } else o.setData({
                    toastHidden: !1,
                    moreHidden: "none",
                    msg: "当前网络异常，请稍后再试",
                    bol: !0
                });
            },
            complete: function() {
                o.setData({
                    loadHidden: !0
                });
            }
        });
    },
    onLoad: function(t) {
        var a = t.Listurl, e = t.TopName;
        this.setData({
            Listurl: a,
            TopName: e
        });
    },
    onShow: function() {
        this.loadData(0, 8);
    },
    delet: function(a) {
        var e = this.data.Listurl, o = a.target.dataset.index, i = a.target.dataset.list, n = this, s = i[o].id;
        wx.showModal({
            title: "提示",
            content: "确定要删除吗？",
            success: function(a) {
                a.confirm && wx.request({
                    url: t.url + "addon/" + e + "deletContract",
                    data: {
                        id: s
                    },
                    method: "POST",
                    header: {
                        "content-type": "application/x-www-form-urlencoded",
                        Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
                    },
                    success: function(t) {
                        i.splice(o, 1), n.setData({
                            List1: i
                        });
                    }
                });
            }
        });
    },
    Open: function(t) {
        var a = t.target.dataset.index, e = t.target.dataset.list, o = this.data.TopName;
        "我起草的合同" == o && this.openDetail1(a, e), "委托起草的合同" == o && this.openDetail2(a, e), 
        "委托审查的合同" == o && this.openDetail3(a, e);
    },
    openDetail1: function(t, a) {
        var e = wx.getStorageSync("PHPSESSID"), o = a[t].htbase, i = a[t].id;
        "M" == o && wx.redirectTo({
            url: "../../pages/Modelht/Modelht?id=" + i + "&url=Smcontract/Smcontract/ContractDetail&url2=Smcontract/Smcontract/editContract&sessin=" + e + "&Listurl=" + this.data.Listurl + "&TopName=" + this.data.TopName
        }), "S" == o && wx.redirectTo({
            url: "../../pages/MySht/MySht?id=" + i + "&url=Smcontract/Smcontract/ContractDetail&url2=Smcontract/Smcontract/editContract&sessin=" + e + "&Listurl=" + this.data.Listurl + "&TopName=" + this.data.TopName
        });
    },
    openDetail2: function(t, a) {
        var e = wx.getStorageSync("PHPSESSID"), o = a[t].id;
        wx.redirectTo({
            url: "../../pages/Modelht/Modelht?id=" + o + "&url=Wdraft/Wdraft/ContractDetail&url2=Wdraft/Wdraft/editContract&sessin=" + e + "&Listurl=" + this.data.Listurl + "&TopName=" + this.data.TopName
        });
    },
    openDetail3: function(t, a) {
        var e = wx.getStorageSync("PHPSESSID"), o = a[t].id;
        wx.redirectTo({
            url: "../../pages/Modelht2/Modelht2?id=" + o + "&url=Examhtong/Examhtong/ContractDetail&url2=Examhtong/Examhtong/editContract&sessin=" + e + "&Listurl=" + this.data.Listurl + "&TopName=" + this.data.TopName
        });
    },
    toExam: function(t) {
        var a = t.target.dataset.index, e = t.target.dataset.list;
        if (e[a].htbase) o = "SM"; else var o = "WT";
        var i = e[a].id;
        wx.navigateTo({
            url: "../../pages/ExamMy/ExamMy?id=" + i + "&htbase=" + o
        });
    },
    toInfo: function(a) {
        var e = a.target.dataset.index, o = a.target.dataset.list[e].id, i = this;
        wx.showToast({
            title: "数据加载中",
            icon: "loading",
            duration: 2e4
        }), wx.request({
            url: t.url + "addon/Wdraft/Wdraft/ContractInfos",
            data: {
                id: o
            },
            method: "GET",
            header: {
                "Content-Type": "application/json",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(t) {
                wx.hideToast(), i.setData({
                    ht: t.data,
                    condition: !1,
                    CsEmail: wx.getStorageSync("CsEmail"),
                    CsWxnum: wx.getStorageSync("CsWxnum")
                });
            },
            fail: function(t) {
                wx.hideToast(), wx.showToast({
                    title: "无法连接网络",
                    icon: "loading",
                    duration: 2500
                });
            }
        });
    },
    toInfo2: function(a) {
        var e = a.target.dataset.index, o = a.target.dataset.list[e].id, i = this;
        wx.showToast({
            title: "数据加载中",
            icon: "loading",
            duration: 2e4
        }), wx.request({
            url: t.url + "addon/Examhtong/Examhtong/ContractInfos",
            data: {
                id: o
            },
            method: "GET",
            header: {
                "Content-Type": "application/json",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(t) {
                wx.hideToast(), i.setData({
                    ht: t.data,
                    condition: !1,
                    CsEmail: wx.getStorageSync("CsEmail"),
                    CsWxnum: wx.getStorageSync("CsWxnum")
                });
            },
            fail: function(t) {
                wx.hideToast(), wx.showToast({
                    title: "无法连接网络",
                    icon: "loading",
                    duration: 2500
                });
            }
        });
    },
    loadMore: function(t) {
        this.loadData(0, 300), this.setData({
            msg: "",
            bol: !0
        });
    },
    Operate: function(t) {
        var a = this, e = this.data.TopName;
        "我起草的合同" == e && wx.showActionSheet({
            itemList: [ "打开合同", "删除合同", "委托审查合同" ],
            success: function(e) {
                console.log(e.tapIndex), 0 == e.tapIndex && a.Open(t), 1 == e.tapIndex && a.delet(t), 
                2 == e.tapIndex && a.toExam(t);
            },
            fail: function(t) {
                console.log(t.errMsg);
            }
        }), "委托起草的合同" == e && wx.showActionSheet({
            itemList: [ "打开合同", "查看委托信息", "委托审查合同" ],
            success: function(e) {
                console.log(e.tapIndex), 0 == e.tapIndex && a.Open(t), 1 == e.tapIndex && a.toInfo(t), 
                2 == e.tapIndex && a.toExam(t);
            },
            fail: function(t) {
                console.log(t.errMsg);
            }
        }), "委托审查的合同" == e && wx.showActionSheet({
            itemList: [ "查看委托信息", "查看审查意见" ],
            success: function(e) {
                console.log(e.tapIndex), 0 == e.tapIndex && a.toInfo2(t), 1 == e.tapIndex && a.Open(t);
            },
            fail: function(t) {
                console.log(t.errMsg);
            }
        });
    },
    backtoCover: function() {
        wx.switchTab({
            url: "../MyCover/MyCover"
        });
    },
    closepage: function() {
        this.setData({
            condition: !0
        });
    }
});